<template>
  <div class="new-year-container">
    <div class="stars"></div>
    <div v-if="!isNewYear" class="countdown">
      <h1 class="title">距离2025年还有</h1>
      <div class="time-blocks">
        <div class="time-block">
          <span class="number">{{ days }}</span>
          <span class="label">天</span>
        </div>
        <div class="time-block">
          <span class="number">{{ hours }}</span>
          <span class="label">时</span>
        </div>
        <div class="time-block">
          <span class="number">{{ minutes }}</span>
          <span class="label">分</span>
        </div>
        <div class="time-block">
          <span class="number">{{ seconds }}</span>
          <span class="label">秒</span>
        </div>
      </div>
    </div>
    <div v-else class="celebration">
      <h1 class="celebration-text">新年快乐</h1>
    </div>
    <div class="fireworks-container" :class="{ 'celebration-mode': isNewYear }">
      <div v-for="n in (isNewYear ? 24 : 12)" :key="n" class="firework">
        <div class="explosion"></div>
        <div v-for="p in 12" :key="p" class="particles">
          <span v-for="s in 8" :key="s" :style="getRandomColor()"></span>
        </div>
      </div>
    </div>
    <div class="year-text" :class="{ 'celebration-mode': isNewYear }">
      <span>2</span>
      <span>0</span>
      <span>2</span>
      <span>5</span>
    </div>
    <footer class="copyright">
      <p>Copyright ©2025 by limin. All rights reserved. | <a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener">粤ICP备2023063724号</a></p>
    </footer>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const days = ref(0)
const hours = ref(0)
const minutes = ref(0)
const seconds = ref(0)
const isNewYear = ref(false)

const colors = [
  '#ff0000', '#00ff00', '#0000ff', '#ffff00', 
  '#ff00ff', '#00ffff', '#ff8800', '#ff0088',
  '#88ff00', '#0088ff', '#ff5555', '#55ff55'
]

const getRandomColor = () => {
  const color = colors[Math.floor(Math.random() * colors.length)]
  return {
    background: color,
    boxShadow: `0 0 10px ${color}, 0 0 20px ${color}`
  }
}

const calculateTimeLeft = () => {
  const now = new Date()
  const newYear = new Date('2025-01-01 00:00:00')
  const difference = newYear - now

  if (difference <= 0) {
    isNewYear.value = true
    if (timer) clearInterval(timer)
    return
  }

  days.value = Math.floor(difference / (1000 * 60 * 60 * 24))
  hours.value = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
  minutes.value = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60))
  seconds.value = Math.floor((difference % (1000 * 60)) / 1000)
}

let timer = null

onMounted(() => {
  calculateTimeLeft()
  timer = setInterval(calculateTimeLeft, 1000)
})

onUnmounted(() => {
  if (timer) clearInterval(timer)
})
</script>

<style scoped>
.new-year-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #000428, #004e92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.stars {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(2px 2px at 20px 30px, #eee, rgba(0,0,0,0)),
                    radial-gradient(2px 2px at 40px 70px, #fff, rgba(0,0,0,0)),
                    radial-gradient(2px 2px at 50px 160px, #ddd, rgba(0,0,0,0)),
                    radial-gradient(2px 2px at 90px 40px, #fff, rgba(0,0,0,0));
  background-repeat: repeat;
  background-size: 200px 200px;
  animation: twinkle 4s infinite;
}

.countdown {
  z-index: 1;
  text-align: center;
  color: white;
  padding: 40px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  box-shadow: 0 25px 45px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: glow 3s infinite;
}

.title {
  font-size: 3rem;
  margin-bottom: 40px;
  text-shadow: 0 0 20px rgba(255,255,255,0.3);
  background: linear-gradient(45deg, #fff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 600;
  letter-spacing: 2px;
}

.time-blocks {
  display: flex;
  gap: 30px;
  justify-content: center;
}

.time-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.3s ease;
}

.time-block:hover {
  transform: translateY(-5px);
}

.number {
  font-size: 5rem;
  font-weight: bold;
  background: linear-gradient(45deg, #FFD700, #FFA500, #ff4d4d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(255,215,0,0.3);
  font-family: 'Arial', sans-serif;
  line-height: 1;
  margin-bottom: 10px;
}

.label {
  font-size: 1.4rem;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 500;
  text-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.fireworks-container {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
}

.firework {
  position: absolute;
  bottom: 0;
  width: 6px;
  height: 6px;
  animation: launch var(--duration, 2.5s) infinite;
}

.celebration-mode .firework {
  --duration: 2s;
}

.firework:nth-child(1) { left: 5%; animation-delay: 0.2s; }
.firework:nth-child(2) { left: 15%; animation-delay: 0.4s; }
.firework:nth-child(3) { left: 25%; animation-delay: 0.6s; }
.firework:nth-child(4) { left: 35%; animation-delay: 0.8s; }
.firework:nth-child(5) { left: 45%; animation-delay: 1.0s; }
.firework:nth-child(6) { left: 55%; animation-delay: 1.2s; }
.firework:nth-child(7) { left: 65%; animation-delay: 1.4s; }
.firework:nth-child(8) { left: 75%; animation-delay: 1.6s; }
.firework:nth-child(9) { left: 85%; animation-delay: 1.8s; }
.firework:nth-child(10) { left: 95%; animation-delay: 2.0s; }
.firework:nth-child(11) { left: 10%; animation-delay: 2.2s; }
.firework:nth-child(12) { left: 20%; animation-delay: 2.4s; }
.firework:nth-child(13) { left: 30%; animation-delay: 0.3s; }
.firework:nth-child(14) { left: 40%; animation-delay: 0.5s; }
.firework:nth-child(15) { left: 50%; animation-delay: 0.7s; }
.firework:nth-child(16) { left: 60%; animation-delay: 0.9s; }
.firework:nth-child(17) { left: 70%; animation-delay: 1.1s; }
.firework:nth-child(18) { left: 80%; animation-delay: 1.3s; }
.firework:nth-child(19) { left: 90%; animation-delay: 1.5s; }
.firework:nth-child(20) { left: 12%; animation-delay: 1.7s; }
.firework:nth-child(21) { left: 22%; animation-delay: 1.9s; }
.firework:nth-child(22) { left: 32%; animation-delay: 2.1s; }
.firework:nth-child(23) { left: 42%; animation-delay: 2.3s; }
.firework:nth-child(24) { left: 52%; animation-delay: 2.5s; }

.explosion {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
}

.particles {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}

.particles span {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  opacity: 0;
  transform-origin: center 150px;
  animation: bang 2s ease-out infinite;
}

.particles span:nth-child(1) { transform: rotate(0deg); }
.particles span:nth-child(2) { transform: rotate(60deg); }
.particles span:nth-child(3) { transform: rotate(120deg); }
.particles span:nth-child(4) { transform: rotate(180deg); }
.particles span:nth-child(5) { transform: rotate(240deg); }
.particles span:nth-child(6) { transform: rotate(300deg); }

@keyframes launch {
  0% {
    bottom: -20px;
    opacity: 1;
    transform: scale(1);
  }
  50% {
    bottom: 50%;
    opacity: 1;
    transform: scale(1);
  }
  51% {
    bottom: 50%;
    transform: scale(2);
  }
  100% {
    bottom: 50%;
    opacity: 0;
    transform: scale(0);
  }
}

@keyframes bang {
  0% {
    opacity: 1;
    transform: rotate(var(--angle, 0deg)) translateY(0);
  }
  50% {
    opacity: 0.7;
    transform: rotate(var(--angle, 0deg)) translateY(-100px);
  }
  100% {
    opacity: 0;
    transform: rotate(var(--angle, 0deg)) translateY(-200px);
  }
}

.year-text {
  position: absolute;
  bottom: 10%;
  font-size: 6rem;
  font-weight: bold;
  color: #FFD700;
  text-shadow: 0 0 20px rgba(255,215,0,0.8);
}

.year-text span {
  display: inline-block;
  animation: bounce 2s infinite;
}

.year-text span:nth-child(1) { animation-delay: 0.1s; }
.year-text span:nth-child(2) { animation-delay: 0.2s; }
.year-text span:nth-child(3) { animation-delay: 0.3s; }
.year-text span:nth-child(4) { animation-delay: 0.4s; }

@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

.celebration {
  z-index: 1;
  text-align: center;
}

.celebration-text {
  font-size: 6rem;
  color: #FFD700;
  text-shadow: 0 0 20px rgba(255,215,0,0.8);
  animation: scale 2s infinite;
}

.fireworks-container.celebration-mode {
  z-index: 2;
}

@keyframes scale {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

.year-text.celebration-mode {
  animation: float 3s ease-in-out infinite;
  z-index: 3;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0) scale(1.2);
  }
  50% {
    transform: translateY(-30px) scale(1.4);
  }
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 25px 45px rgba(0, 0, 0, 0.2);
  }
  50% {
    box-shadow: 0 25px 45px rgba(255, 215, 0, 0.2);
  }
}

.copyright {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  padding: 15px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.copyright p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  margin: 0;
}

.copyright a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: color 0.3s ease;
}

.copyright a:hover {
  color: #FFD700;
}

@media (max-width: 768px) {
  .countdown {
    padding: 20px;
    border-radius: 20px;
  }

  .title {
    font-size: 2rem;
    margin-bottom: 30px;
  }

  .time-blocks {
    gap: 15px;
  }

  .time-block {
    min-width: 80px;
    padding: 15px;
  }

  .number {
    font-size: 3rem;
  }

  .label {
    font-size: 1rem;
  }

  .copyright {
    padding: 10px;
  }
  
  .copyright p {
    font-size: 0.8rem;
  }
}
</style> 